<template>
  <div class="container">
    <el-row :gutter="20">
      <el-col :span="8">
        <el-form :model="attendance.workTime">
          <el-form-item label="班组：">
            <el-select v-model="teamValue" placeholder="选择班组" @change="changClient">
              <el-option
                v-for="item in teamList"
                :key="item.CLIENT_NO"
                :label="item.CLIENT_NAME"
                :value="item.CLIENT_NO"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="上午：" style="height: 38px">
            <el-time-picker
              style="height: 38px"
              is-range
              v-model="attendance.workTime.am"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              placeholder="选择时间范围"
              value-format="HH:mm:ss"
              step="00:00:01"
            ></el-time-picker>
          </el-form-item>
          <el-form-item label="下午：" style="height: 38px">
            <el-time-picker
              style="height: 38px"
              is-range
              v-model="attendance.workTime.pm"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              placeholder="选择时间范围"
              value-format="HH:mm:ss"
              step="00:00:01"
            ></el-time-picker>
          </el-form-item>
          <div class="attendance_btns">
            <el-button type="primary" @click="setWorkingHours">保 存</el-button>
            <!-- <el-button type="danger" @click="closeWorkTime">关 闭</el-button> -->
          </div>
        </el-form>
      </el-col>
      <!-- <el-col :span="6">
          <el-form ref="form" :model="form">
            
          </el-form>
      </el-col>-->
    </el-row>
  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'
import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {
    return {
      attendance: {
        workTime: {

          show: false,
          am: [],
          pm: [],
          ClientNo: ''
        }
      },
      teamValue: '',
      teamList: []
    }
  },
  created () {
    // this.getTeamList();
    this.openWorkTime();
  },
  methods: {
    async openWorkTime () {
      // this.attendance.workTime.show = true
      // this.attendance.records.show = false
      // 获取时间
      // this.attendance.workTime.am = []
      // this.attendance.workTime.pm = []

      const { data } = await this.$Http.get('DataListCompany/GetWorkeTimeApi?ClientNo=' + localStorage.getItem('CLIENT_NO'))
      // let data = [{"CLIENT_NO":"0000009","CLIENT_NAME":"博德尔清扫队","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090101","CLIENT_NAME":"丰年班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090201","CLIENT_NAME":"华明陈明年班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090202","CLIENT_NAME":"华明陈毅班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090203","CLIENT_NAME":"华明拱富生班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090204","CLIENT_NAME":"华明侯孟余班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090205","CLIENT_NAME":"华明姜炳莲班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090206","CLIENT_NAME":"华明孙克亮班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090207","CLIENT_NAME":"华明孙克文班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090208","CLIENT_NAME":"华明杨霞班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090209","CLIENT_NAME":"华明张彩娥班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090210","CLIENT_NAME":"华明张德栓班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090301","CLIENT_NAME":"华新班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090401","CLIENT_NAME":"金钟崔连顺班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090402","CLIENT_NAME":"金钟郝宝水班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090403","CLIENT_NAME":"金钟郝富刚班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090404","CLIENT_NAME":"金钟孙健班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090405","CLIENT_NAME":"金钟孙学英班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090406","CLIENT_NAME":"金钟魏占庆班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090502","CLIENT_NAME":"开发区南班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090501","CLIENT_NAME":"开发区北班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090601","CLIENT_NAME":"成林道班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090602","CLIENT_NAME":"津滨大道班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090608","CLIENT_NAME":"万新南片班组","AM_IN":"07:00:00","AM_OUT":"11:30:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090603","CLIENT_NAME":"天山南路班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090604","CLIENT_NAME":"东城家园班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090605","CLIENT_NAME":"万新孙建和班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090606","CLIENT_NAME":"百合春天班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090607","CLIENT_NAME":"万新王树友班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090609","CLIENT_NAME":"昆仑路班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090610","CLIENT_NAME":"好新家园班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090611","CLIENT_NAME":"秋丽家园班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090612","CLIENT_NAME":"登州路班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"},{"CLIENT_NO":"00000090701","CLIENT_NAME":"张贵庄班组","AM_IN":"06:30:00","AM_OUT":"11:00:00","PM_IN":"13:30:00","PM_OUT":"17:00:00"}]
      this.teamList = data
      this.teamValue = data[0].CLIENT_NO
      this.changClient()
    },
    changClient () {
      this.attendance.workTime.am = []
      this.attendance.workTime.pm = []

      let item = this.teamList.find(val => val.CLIENT_NO == this.teamValue)

      if (!item.AM_IN.split(':')[2]) item.AM_IN += ':00'
      if (!item.AM_OUT.split(':')[2]) item.AM_OUT += ':00'

      this.attendance.workTime.am.push(item.AM_IN, item.AM_OUT)
      this.attendance.workTime.pm.push(item.PM_IN, item.PM_OUT)
    },
    // async getTeamList () {

    //   const { data } = await this.$Http.get('DataListCompany/GetCleanerGroupListApi?ClientNo=' + localStorage.getItem('CLIENT_NO'))
      
    // },
    // 考勤管理--设定工作时间
    async setWorkingHours () {
      const params = {
        AmIn: this.attendance.workTime.am[0],
        AmOut: this.attendance.workTime.am[1],
        PmIn: this.attendance.workTime.pm[0],
        PmOut: this.attendance.workTime.pm[1],
        ClientNo: this.teamValue
      }
      const { data } = await this.$Http.get('DataListCompany/UpdateWorkerWorkTimeApi', { params })
      console.log(data)
      if (data.IsSucess) {
        this.openWorkTime();
        this.$message({
          showClose: true,
          message: '修改成功',
          type: 'success'
        })
      } else {
        this.$message({
          showClose: true,
          message: '修改失败',
          type: 'error'
        })
      }
    },
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
</style>